/*
 * @Author: fjxcjm 3157329468@qq.com
 * @Date: 2025-03-11 18:51:01
 * @LastEditors: fjxcjm 3157329468@qq.com
 * @LastEditTime: 2025-03-11 19:17:22
 * @FilePath: \RuoYi-Vue-master\ruoyi-admin\src\main\java\com\ruoyi\seedlingSys\controller\ZhongmiaoController.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package com.ruoyi.seedlingSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.seedlingSys.domain.Zhongmiao;
import com.ruoyi.seedlingSys.service.IZhongmiaoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 种苗繁育管理Controller
 * 
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/seedlingSys/zhongmiao")
public class ZhongmiaoController extends BaseController {
    @Autowired
    private IZhongmiaoService zhongmiaoService;

    /**
     * 查询种苗繁育管理列表
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:zhongmiao:list')")
    @GetMapping("/list")
    public TableDataInfo list(Zhongmiao zhongmiao) {
        startPage();
        List<Zhongmiao> list = zhongmiaoService.selectZhongmiaoList(zhongmiao);
        return getDataTable(list);
    }

    /**
     * 导出种苗繁育管理列表
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:zhongmiao:export')")
    @Log(title = "种苗繁育管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Zhongmiao zhongmiao) {
        List<Zhongmiao> list = zhongmiaoService.selectZhongmiaoList(zhongmiao);
        ExcelUtil<Zhongmiao> util = new ExcelUtil<Zhongmiao>(Zhongmiao.class);
        util.exportExcel(response, list, "种苗繁育管理数据");
    }

    /**
     * 获取种苗繁育管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:zhongmiao:query')")
    @GetMapping(value = "/{zhongMiaoID}")
    public AjaxResult getInfo(@PathVariable("zhongMiaoID") Long zhongMiaoID) {
        return success(zhongmiaoService.selectZhongmiaoByZhongMiaoID(zhongMiaoID));
    }

    /**
     * 新增种苗繁育管理
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:zhongmiao:add')")
    @Log(title = "种苗繁育管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Zhongmiao zhongmiao) {
        int rows = zhongmiaoService.insertZhongmiao(zhongmiao);
        if (rows > 0) {
            return success("新增种苗成功，已自动创建对应批次");
        }
        return error("新增种苗失败");
    }

    /**
     * 修改种苗繁育管理
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:zhongmiao:edit')")
    @Log(title = "种苗繁育管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Zhongmiao zhongmiao) {
        return toAjax(zhongmiaoService.updateZhongmiao(zhongmiao));
    }

    /**
     * 删除种苗繁育管理
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:zhongmiao:remove')")
    @Log(title = "种苗繁育管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{zhongMiaoIDs}")
    public AjaxResult remove(@PathVariable Long[] zhongMiaoIDs) {
        return toAjax(zhongmiaoService.deleteZhongmiaoByZhongMiaoIDs(zhongMiaoIDs));
    }
}
